package com.shawn.integeration.business.studentmanager.controller;

import com.shawn.integeration.business.studentmanager.model.Student;
import com.shawn.integeration.business.studentmanager.service.IStudentService;
import com.shawn.integeration.common.model.controller.BaseController;
import com.shawn.integeration.common.model.res.GenericResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * 学生管理控制层
 *
 * @author: shawn
 * @Date: 2023/12/28 13:52
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/student")
public class StudentController extends BaseController {
    @Resource
    private IStudentService studentService;

    @PostMapping(value = "/add")
    public GenericResponse add(Student student) {
        return toRes(studentService.save(student));
    }


    @DeleteMapping("/delete/{studentIds}")
    public GenericResponse delete(@PathVariable Long[] studentIds) {
        return toRes(studentService.removeByIds(Arrays.asList(studentIds)));
    }

    @PostMapping(value = "/edit")
    public GenericResponse edit(Student Student) {
        return toRes(studentService.updateById(Student));
    }

    @GetMapping(value = "/{studentId}")
    public GenericResponse getInfo(@PathVariable("studentId") Long studentId) {
        return GenericResponse.success(studentService.getById(studentId));
    }
}
